<script src="http://localhost/wordpress/wp-content/plugins/steel/jquery-1.4.4.js"></script>
                    <script src="http://localhost/wordpress/wp-content/plugins/steel/home.js"></script>
<?php
require('../../../wp-config.php');
$plugin_url = trailingslashit( WP_PLUGIN_URL.'/'. dirname( plugin_basename(__FILE__)));
global $wpdb;
$where = '1 = 1';
if(intval($_POST['bed_room']) > 0){
    $where .= ' AND bed_room = '.intval($_POST['bed_room']);
}
if(intval($_POST['type']) > 1){
    $where .= ' AND type = '.intval($_POST['type']);
}
if(intval($_POST['location']) > 1){
    $where .= ' AND location = '.intval($_POST['location']);
}
if(intval($_POST['from']) > 0){
    $where .= ' AND price >= '.intval($_POST['from']);
}
if(intval($_POST['to']) > 0){
    $where .= ' AND price <= '.intval($_POST['to']);
}
if($_POST['where'] != ''){
    $where .= ' AND id IN (SELECT id_house FROM wp_value WHERE id_att IN ('.$_POST['where'].'))';
}
$pageNum = 1;
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}
$rowsPerPage = 5;
$offset = ($pageNum - 1) * $rowsPerPage;
echo '<h1>Search result</h1>';
$stt = 1;foreach($wpdb->get_results("SELECT * FROM wp_house WHERE ".$where. " LIMIT $offset, $rowsPerPage") as $row):
        $type = substr($wpdb->get_var("SELECT link FROM wp_image WHERE id_house=".$row->id." AND main=1"),-4);
        $type = substr($wpdb->get_var("SELECT link FROM wp_image WHERE id_house=".$row->id." AND main=1"),-4);
?>
<div class="menu<?php echo ($stt % 2) ?>" style="height: 110px;">
    <a href="<?php echo $plugin_url;?>detail.php?id=<?php echo $row->id;?>" target="_blank"><?php echo $row->name;?></a> - <?php echo $row->address;?> - <?php echo $row->price;?>&nbsp;$<br />
    <div style="float:left;"><img src="<?php echo $wpdb->get_var("SELECT link FROM wp_image WHERE id_house=".$row->id); ?>" width="100" onclick="window.open('<?php echo $plugin_url;?>detail.php?id=<?php echo $row->id;?>');" style="cursor:pointer;" /></div><div style="margin-left: 110px;"><?php echo nl2br((strlen($row->description) > 200)?substr($row->description,0,200).'...':$row->description);?></div>
    
</div>
<?php $stt++;endforeach;
$maxPage = ceil($wpdb->get_var("SELECT COUNT(*) FROM wp_house WHERE ".$where)/$rowsPerPage);?>
<style>
.menu0 {
        background-color:#dcdcdc;
}
.menu1 {
    background-color:#f1f1f1;
}
</style>
<center>
    <?php for($i=1;$i<=$maxPage;$i++){
     if($i != $pageNum){
         echo '<a href="javascript:search('.$i.')">'.$i.'</a>';
     }
     else
     {
         echo $i;
     }
     echo '&nbsp;';
    }?>
</center>